package com.zjn.serviceb.service.Imp;

import com.zjn.entity.Identity;
import com.zjn.entity.User;
import com.zjn.serviceb.dao.IdentityDao;
import com.zjn.serviceb.service.IdentityService;
import com.zjn.serviceb.service.third.ServiceAFeign;
import lombok.extern.log4j.Log4j2;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author zaker
 * @program: signit_parent
 * @date 2021-03-30 14:23
 */
@Service
public class IdentityServiceImp implements IdentityService {

    private static final Logger LOG = LoggerFactory.getLogger(IdentityServiceImp.class);


    @Autowired
    private IdentityDao identityDao;

    @Autowired
    private ServiceAFeign serviceAFeign;


    @Override
    @Transactional
    public String updateIdentity(Identity identity) {
        LOG.info("更新身份",identity);
        int result=identityDao.updateByPrimaryKeySelective(identity);
        User user=new User();
        user.setId(identity.getId());
        user.setIdentityStatus(identity.getIdentityStatus());
        String userResult=serviceAFeign.UpdateUserInfo(user);
        if (result==1&&userResult.equals("OK")) {
            return "OK";
        }else{
            return "ERROR";
        }

    }



    @Override
    public Identity findIdentity(Identity identity) {
        LOG.info("查询身份",identity);
        return identityDao.selectByParam(identity);
    }

    @Override
    @Transactional
    public String createIdentity(Identity identity) {
        LOG.info("创建身份",identity);
        int result=identityDao.insertSelective(identity);
        if (result==1) {
            return "OK";
        }else{
            return "ERROR";
        }
    }

}
